package renguanyu.app.auth4fx.service.role;

import renguanyu.app.auth4fx.dao.role.RolePermissionDao;
import renguanyu.app.auth4fx.model.role.RolePermissionDto;
import renguanyu.app.auth4fx.model.user.UserRoleDto;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

public class RolePermissionService {

    public static List<Map<String, Object>> queryUnownedPermissionList(RolePermissionDto rolePermissionDto){
        String roleId = rolePermissionDto.getRoleId();
        List<Map<String, Object>> unownedPermissionList = RolePermissionDao.queryUnownedPermissionList(roleId);
        return  unownedPermissionList;
    }

    public static List<Map<String, Object>> queryOwnedPermissionList(RolePermissionDto rolePermissionDto){
        String roleId = rolePermissionDto.getRoleId();
        List<Map<String, Object>> ownedPermissionList = RolePermissionDao.queryOwnedPermissionList(roleId);
        return ownedPermissionList;
    }

    public static int[] saveRolePermissionList(Integer size, String roleId, List<String> permissionIds){
        return RolePermissionDao.saveRolePermissionList(size,roleId,permissionIds);
    }

    public static int deleteRolePermissionList(UserRoleDto rolePermissionDto) {
        List<String> ids = rolePermissionDto.getIds();
        String inSql = ids.stream().map(id -> "?").collect(Collectors.joining(","));
        return RolePermissionDao.deleteRolePermissionList(ids,inSql);
    }
}
